<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('暂付款')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form id="form-detail-edit" style="font-size: 15px">
            <div class="form-group">
                <label class="col-xs-4 control-label text-right">客户姓名：</label>
                <div class="col-xs-6">
                    <label class="text-center" th:text="${payInfo.hhUser.userName}" id="userName"></label>
                </div>
            </div>
            <div class="form-group">
                <label>&nbsp;&nbsp;&nbsp;</label>
            </div>
            <div class="form-group">
                <label class="col-xs-4 control-label text-right">累计金额：</label>
                <div class="col-xs-6">
                    <label class="text-center" th:text="${payInfo.hhUser.userAccount}" id="totalMoney"></label>
                </div>
            </div>
            <div class="form-group">
                <label>&nbsp;&nbsp;&nbsp;</label>
            </div>
            <div class="form-group">
                <label class="col-xs-4 control-label text-right">付款金额：</label>
                <div class="col-xs-3">
                    <input class="form-control" type="text" id="payMoney">
                </div>
                <div class="col-xs-4 text-left">
                    <button class="btn btn-warning" type="button" onclick="payConfirm()"><i class="glyphicon glyphicon-yen"></i>&nbsp;暂付款</button>
                </div>
            </div>
            <div class="form-group">
                <label>&nbsp;&nbsp;&nbsp;</label>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var hhUser = [[${payInfo.hhUser}]];
        var hhOrder = [[${payInfo.hhOrder}]];

        //确认付款
        function payConfirm() {
            var payAmount = $('#payMoney').val();
            var num = /^[+-]?[0-9]+(\.[0-9]{1,2})?$/;
            if (!num.test(payAmount)) {
                $.modal.alertError("输入有误，请重新输入！");
                return false;
            }
            $.modal.confirm(hhUser.userName + " 确认付款: ￥" + payAmount + " 吗?", function () {
                payPost("order/manage/pay", hhOrder.orderId, '1', payAmount);
            });
        }

        //退货付款
        function payReturn() {
            var payAmount = $('#returnMoney').val();
            var num = /^[+-]?[0-9]+(\.[0-9]{1,2})?$/;
            if (!num.test(payAmount)) {
                $.modal.alertError("输入有误，请重新输入！");
                return false;
            }
            $.modal.confirm(hhUser.userName + " 确认退货: ￥" + payAmount + " 结算吗?", function () {
                payPost("close/manage/closeReturn", hhOrder.orderId, '2', payAmount);
            });
        }

        //退货开单
        function createReturn() {
            var thisIndex = parent.layer.getFrameIndex(window.name);
            var index = parent.layer.open({
                type: 2,
                area: ['800px', '700px'],
                shade: 0.3,
                title: '添加商品',
                content: ctx + "order/manage/addReturn/" + hhOrder.orderId,
                btn: [],
                end: function () {
                    $.table.refresh();
                    parent.layer.close(thisIndex);
                }
            });
            parent.layer.full(index);
        }

        function payPost(url, orderId, payType, payAmount) {
            $.ajax({
                type: "post",
                url: ctx + url,
                data: {
                    "orderId": orderId,
                    "payType": payType,
                    "payAmount": payAmount
                },
                success: function(result) {
                    if (result.code == 0) {
                        $.modal.alertSuccess("操作成功！");
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 500);
                    }
                }
            })
        }
    </script>
</body>
</html>